package com.doyens.controller;

import com.alibaba.nacos.api.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doyens.domain.*;
import com.doyens.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
//    public Result
    @PostMapping("/list")
    public Result list(@RequestBody TeacherDto teacherDto){
        Page<Teacher> pageInfo=new Page<>(teacherDto.getPage(),teacherDto.getPageSize());
       LambdaQueryWrapper<Teacher> wrapper=new LambdaQueryWrapper<>();
       wrapper.eq(teacherDto.getCid()!=null,Teacher::getCid,teacherDto.getCid());
       wrapper.eq(teacherDto.getDid()!=null,Teacher::getDid,teacherDto.getDid());
       wrapper.eq(teacherDto.getPid()!=null,Teacher::getPid,teacherDto.getPage());
       if(teacherDto.getStartdate()!=null){
           wrapper.ge(Teacher::getTdate,teacherDto.getStartdate());
       }
        if(teacherDto.getEnddate()!=null){
            wrapper.ge(Teacher::getTdate,teacherDto.getEnddate());
        }

        Page<Teacher> page = teacherService.page(pageInfo, wrapper);
        return new Result("查询所有成功",page,20000);
    }
    @PostMapping("/add")
    public Result add(@RequestBody TeacherStudent teacherStudent){
      return new Result("添加成功",teacherService.add(teacherStudent),20000) ;
    }

    @PostMapping("/update")
    public Result update(@RequestBody TeacherStudent teacherStudent){
        return new Result("修改成功",teacherService.update1(teacherStudent),20000);
    }

    @PostMapping("/del")
    public Result del(@RequestBody DelStudent delStudent){
      return new Result("删除成功",teacherService.delStudent(delStudent),20000);
    }
    @PostMapping("/delMany")
    public Result delMany(@RequestBody DelStudent delStudent){
        return new Result("批量删除成功",teacherService.delManyStudent(delStudent),20000);
    }




}
